package io.renren.modules.sys.util;

import java.text.SimpleDateFormat;
import java.util.Date;


public class DateUtil {



	public static String formatDate(Date date, String format){
		String result="";
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		if(date!=null){
			result=sdf.format(date);
		}
		return result;
	}
	
	
	public static Date formatString(String str, String format) throws Exception {
		if(StringUtil.isEmpty(str)){
			return null;
		}
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		return sdf.parse(str);
	}

	public static Date formatdate(Date str, String format) throws Exception {
		SimpleDateFormat df = new SimpleDateFormat(format);//设置日期格式


		return df.parse(df.format(str));
	}

	public static String getCurrentDateStr()throws Exception {
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
		return sdf.format(date);
	}
	public static String getCurrentDateStr(String format)throws Exception {
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat(format);
		return sdf.format(date);
	}
	public static String getCurrentYear(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
		Date date = new Date();
		return sdf.format(date);
	}
}
